import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';
import globalInfo from '../utils/GlobalInfo';
import log from '../utils/Log';
import display from '@ohos.display';

const TAG = 'EntryAbility'

export default class EntryAbility extends UIAbility {
  onCreate(want, launchParam) {
    log.info(TAG, 'Ability onCreate')
    globalInfo.context = this.context
    // globalInfo.isLogin = true
    const myDisplay = display.getDefaultDisplaySync()
    log.info(TAG, 'myDisplay.width: ' + myDisplay.width)
    globalInfo.screenWidth = myDisplay.width
  }

  onDestroy() {
    log.info(TAG, 'Ability onDestroy')
  }

  onWindowStageCreate(windowStage: window.WindowStage) {
    // Main window is created, set main page for this ability
    log.info(TAG, 'Ability onWindowStageCreate');
    windowStage.loadContent('pages/MainFrame', (err, data) => {
      if (err.code) {
        log.error(TAG, 'loadContent failed err: ' + JSON.stringify(err))
        return
      }
      log.info(TAG, 'loadContent succeeded data: ' + JSON.stringify(data))
    });

    windowStage.getMainWindow().then((window) => {
      // window.setWindowLayoutFullScreen(true)
      let sysBarProps: window.SystemBarProperties = {
        statusBarColor: '#ffffff',
        navigationBarColor: '#ffffff',
        // 以下两个属性从API Version 8开始支持
        statusBarContentColor: '#000000',
        navigationBarContentColor: '#000000'
      }
      window.setWindowSystemBarProperties(sysBarProps)
    })
  }

  onWindowStageDestroy() {
    // Main window is destroyed, release UI related resources
    log.info(TAG, 'Ability onWindowStageDestroy')
  }

  onForeground() {
    // Ability has brought to foreground
    log.info(TAG, 'Ability onForeground')
  }

  onBackground() {
    // Ability has back to background
    log.info(TAG, 'Ability onBackground')
  }
}
